home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: Robert Kleemann <goose@ix.netcom.con>
- Newsgroups: comp.lang.c++
- Subject: STL and namespaces?
- Date: Tue, 19 Mar 1996 12:34:20 -0800
- Organization: Netcom
- Message-ID: <314F1A4C.2868@ix.netcom.con>
- NNTP-Posting-Host: sea-wa4-21.ix.netcom.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-NETCOM-Date: Tue Mar 19 2:33:52 PM CST 1996
- X-Mailer: Mozilla 2.0 (Win95; I)
-
- I've been using The HP STL (Dec95 version) with the Microsoft VC4
- Compiler for the past few months and have taken Microsoft's
- recommendation to stick all the STL include files in its own namespace
- to avoid global operator conflicts with Microsoft's class library (MFC).
- The name std is recommend by ANSI for the standard template library
- namespace.
-
- After tweaking some of the STL files this has worked pretty well except
- for the following problems:
-
- 1) global operators cannot be accessed without the namespace prefix eg:
- std::string s1;
- std::string s2;
- if (s1==s2) // this doesn't work
- ;
- if (std::operator==(s1,s2)) // this does work
- ;
-
- 2) STL algorithms that use global operators don't work on classes that
- define these operators eg:
-
- class C
- {
- C();
- C(const C& c);
- C& operator=(const C& c);
- friend bool operator==(const C& c1, const C& c2);
- };
- inline bool operator==(const C& c1, const C& c2)
- {
- return true;
- }
- void main()
- {
- std::list<C> container;
- std::list<C>::iterator i;
- // the following line will not compile because
- // find require operator== to be defined for C
- i = std::find( container.begin(), container.end(),
- C() );
- }
-
- The first problem is expected and and although it makes the code less
- readable, it is not a major problem. The second problem has no clear
- workaround and makes me want to stop using namespaces.
-
- My question is: are other people out there using STL with namespaces?
- Have you run into these problems? Have you found better workarounds?
- Can I expect these namespace problems to be fixed in future STL
- implementations or would I be better off including STL in global space
- and instead try sticking MFC in a namespace.
-
- thanx!
- Robert
-